/***************************************************************************
 *   Copyright (C) 2008 by JBox systems
 *   gabi@shaargiora.co.il
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 ***************************************************************************/

#include <QObject>
#include <vector>

#include "version.h"
#include "download.h"

class Controller : public QObject {
	Q_OBJECT

	private:
		Downloader *downloader; /// File downloader
		std::vector<Version> versions; /// Versions
		bool m_keep_downloading; /// Download next file

	public:
		Controller(QObject *parent = 0);
		~Controller();

		/**
			Download single version.
		*/
		void downloadVersion(Version &version);

		/**
			Internal controller connections.
		*/
		void connectController();

	public slots:
		/**
			Start downloading versions.
		*/
		void downloadVersions(std::vector<Version> versions);

		/**
			Prevent the next download from starting.

			Allows current download to finish.
		*/
		void preventNextDownload() { m_keep_downloading = false; }

	private slots:
		/**
			Download next requested file.
		*/
		void downloadNext();

	signals:
		/**
			Downloads finished properly.
		*/
		void downloadsFinished();

		/**
			Downloads aborted by user.
		*/
		void downloadsAborted();

		void dataReadProgress(int, int);

		/**
			Signals a request to the controller to stop downloads.
		*/
		void abortDownloads();

		/**
			Reports current status

			@param status status message (eg. Downloading <filename>).
		*/
		void status(QString message);
};
